import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import {resolve} from "path"

const viteConfig = defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd());

  switch (env.VITE_ENV) {
    case "development":
      console.log("当前运行环境为：开发环境");
      break;
    case "test":
      console.log("当前运行环境为：测试环境");
      console.log(env.VITE_APP_BASE_API);
      break;
      case "production":
        console.log("当前运行环境为：生产环境");
        console.log(env.VITE_APP_BASE_API);
      break;
  }

	// ****打包文件名称****
	let fileName = 'dist'
	// 兼容性，以防打包崩溃
	// fileName = env.VITE_APP_NAME
	return {
		plugins: [vue()],
		define: {
			'process.env': {}
		},
		resolve:{
			alias: [
				{
					find: '@',
					replacement: resolve(__dirname, './src')
				}
			]
		},
		css: {
			preprocessorOptions: {
				scss: {
					api: 'modern-compiler'
				}
			}
		},
		root: process.cwd(),
		assetsInclude: '**/*.xlsx',
		//****这里进行设置文件名****
		build: {
			outDir: fileName,
			assetsPublicPath: './'
		}
	};
});

export default viteConfig;
